<?php
/*
 * @Author: your name
 * @Date: 2019-11-13 10:51:15
 * @LastEditTime: 2020-11-05 16:46:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /ahsmp_3/application/common/service/HostNormalRuleGroupRelation.php
 */
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/12
 * Time: 11:14
 */

namespace app\common\service;


use think\Db;

class HostNormalRuleGroupRelation
{

    /**
     * @name: 表初始化
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-08-16 16:57:20
     */
    function init ($host_id)
    {
        Db::query('INSERT INTO `jzz_host_normal_rule_group_relation` (`group_id`,`host_id`,`status`,`handle`)  select `id`,' . $host_id . ',`default`,`handle` FROM `jzz_ips_normal_rule_group`');
    }

    /**
     * @name 修改
     * @param $condition
     * @param $updateData
     * @return int|string
     * @author wx
     * @date 2019/11/12 11:16
     */
    function modify($condition, $updateData)
    {
        return db('host_normal_rule_group_relation')->where($condition)->update($updateData);
    }

    /**
     * @name: 添加关系
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-09 16:51:52
     */
    function add($host_id)
    {
        if(db('hostNormalRuleGroupRelation')->where('host_id', $host_id)->count() > 0)
        {
            return [];
        }
        db()->query('INSERT INTO `' . config('database.prefix') . 'host_normal_rule_group_relation` (`group_id`,`host_id`,`status`)  select `id`,' . $host_id . ',`default` FROM `' . config('database.prefix') . 'normal_rule_group`');
    }

    /**
     * @name: 删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2019-12-24 13:17:59
     */
    function del ($host_id_a)
    {
        db('hostNormalRuleGroupRelation')->whereIn('host_id', $host_id_a)->delete();
    }

    /**
     * @name 清空
     * @author wx
     * @date 2020/6/28 14:56
     */
    function clear($host_id)
    {
        db('hostNormalRuleGroupRelation')->whereIn('host_id', $host_id)->delete();
    }
}